<template>
  <div class="participate">
    <middle-title title="活动参与情况"></middle-title>
    <div class="topTitle">
      <blue-title title="累计活动参与人数" number="176" unit="人"></blue-title>
    </div>
    <div class="bottomEchart" ref="barEchart"></div>
  </div>
</template>
<script setup>
import { ref, inject, onMounted } from 'vue'
const echarts = inject('echarts')
let barEchart = ref(null)
let myEchart = null
let colorList = [
  'rgba(29, 241, 249, 0)',
  'rgba(29, 241, 249, 0.4)',
  'rgba(29, 241, 249, 0.8)',
  'rgba(29, 241, 249, 1)'
]
let data = {
  xdata: ['10人以下', '10~20人', '20~30人', '30~40人', '40人以上'],
  ydata: [5, 7, 10, 8, 5]
}
onMounted(() => {
  setEchart()
})
const setEchart = () => {
  if (myEchart != null && myEchart != '' && myEchart != undefined) {
    myEchart.dispose() //销毁
  }
  myEchart = echarts.init(barEchart.value, null, { renderer: 'svg' })
  let option = {
    tooltip: {
      trigger: 'axis',
      textStyle: {
        fontSize: 22 // 字体大小
      },
      axisPointer: {
        // Use axis to trigger tooltip
        type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
      }
    },
    grid: {
      left: '0%',
      right: '5%',
      bottom: '3%',
      top: '0%',
      containLabel: true
    },
    xAxis: {
      type: 'value',
      axisTick: {
        show: false
      },
      axisLine: {
        show: true,
        lineStyle: {
          color: '#FFFFFF',
          opacity: 0.4
        }
      },
      splitLine: {
        //修改背景线条样式
        show: false
      },
      axisLabel: {
        show: true,
        fontSize: 14,
        color: '#fff'
      }
    },
    yAxis: {
      type: 'category',
      data: data.xdata,
      axisTick: {
        show: false
      },
      axisLine: {
        show: true,
        lineStyle: {
          color: '#FFFFFF',
          opacity: 0.4
        }
      },
      axisLabel: {
        show: true,
        color: '#fff',
        fontSize: 14
      },
      splitLine: {
        //修改背景线条样式
        show: false
      }
    },
    series: [
      {
        type: 'bar',
        // label: {
        //   show: true,
        //   color: '#fff',
        //   fontSize: 18
        // },
        barWidth: 11,
        emphasis: {
          focus: 'series'
        },
        // showBackground: true, //开启背景
        // backgroundStyle: {
        //   //设置背景样式
        //   color: 'rgba(42, 53, 68, 1)',
        //   barBorderRadius: 10
        // },

        data: data.ydata,
        itemStyle: {
          color: (param) => {
            return new echarts.graphic.LinearGradient(0, 0, 1, 0, [
              { offset: 0, color: colorList[0] },
              { offset: 0.4, color: colorList[1] },
              { offset: 0.8, color: colorList[2] },
              { offset: 1, color: colorList[3] }
            ])
          },
          borderRadius: [0, 20, 20, 0]
        }
      }
    ]
  }
  myEchart.setOption(option)
}
</script>
<style scoped lang="scss">
.participate {
  height: 401px;
  box-sizing: border-box;
  //   background-color: blue;
  .topTitle {
    padding: 2px 0 0px 10px;
  }
  .bottomEchart {
    width: 500px;
    height: 295px;
    // background-color: red;
  }
}
</style>
